const util = require('utils/util.js')
App({
  globalData: {
    apiurl: "https://yj.shzxcx.com/", 
    getVideoList:"https://yj.shzxcx.com/video",
    searchVideoList:"https://yj.shzxcx.com/video/search",
    getHotSearchsUrl:"https://yj.shzxcx.com/video/hotSearch",
    getVideoById:"https://yj.shzxcx.com/video/",
    getFamousListUrl: "https://yj.shzxcx.com/famous",
    getFamousById: "https://yj.shzxcx.com/famous/",
    getOpenid:"https://yj.shzxcx.com/user/getOpenid",
    userOperating:"https://yj.shzxcx.com/user/operating",
    userRecord:"https://yj.shzxcx.com/user/record",
    saveUser:"https://yj.shzxcx.com/user",
    userInfo:null,
    openid:null,
    isShare: false



  },
  onLaunch: function (options){
    console.log(options);
    if (options.scene == 1007 || options.scene == 1008){
      this.globalData.isShare=true;
    }
    console.log('是否分享页面进来');
    console.log(this.globalData.isShare);
    // 登录
    wx.login({
      success: res => {
          //获取openid
        wx.request({
          url: this.globalData.getOpenid,
          method: 'POST',
          data: { code: res.code },
          header: {
            "Content-Type": "application/json"
          },
          success: (res) => {
            console.log(res);
            this.globalData.openid = res.data.data.openid;
            if (this.porcessDataOpenid) {
              this.porcessDataOpenid(res.data);
            }
          }
        })

          //util.http(this.globalData.getOpenid, 'POST', { code: res.code }, this.porcessDataOpenid);
      }
    })

    // 获取用户信息
    wx.getSetting({
      success: res => {
        if (res.authSetting['scope.userInfo']) {
          // 已经授权，可以直接调用 getUserInfo 获取头像昵称，不会弹框
          wx.getUserInfo({
            success: res => {
              // 可以将 res 发送给后台解码出 unionId
              this.globalData.userInfo = res.userInfo

              // 由于 getUserInfo 是网络请求，可能会在 Page.onLoad 之后才返回
              // 所以此处加入 callback 以防止这种情况
              if (this.userInfoReadyCallback) {
                this.userInfoReadyCallback(res)
              }
            }
          })
        }
      }
    })
   
  }/*,
  porcessData: function(res){
    console.log(res);
    this.globalData.openid = res.data.openid;
  }*/

})